package com.ryan.mms.organization.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ryan.framework.dto.DtoUtil;
import com.ryan.framework.tag.pagination.Page;
import com.ryan.mms.organization.dao.OrganizationDao;
import com.ryan.mms.organization.dto.OrganizationDto;
import com.ryan.mms.organization.model.Organization;
import com.ryan.mms.organization.service.OrganizationService;

@Service
public class OrganizationServiceImpl implements OrganizationService<OrganizationDto, Organization, Long> {
	
	@Autowired
	private OrganizationDao<Organization,Long> organizationDao;

	@SuppressWarnings("unchecked")
	private DtoUtil<OrganizationDto,Organization> organizationDtoUtil = DtoUtil.getInstance(OrganizationDto.class, Organization.class);
	
	@Override
	public OrganizationDto save(OrganizationDto dto) {
		return organizationDtoUtil.convertModel2Dto(organizationDao.save(organizationDtoUtil.convertDto2Model(dto)));
	}

	@Override
	public OrganizationDto update(OrganizationDto dto) {
		return save(dto);
	}

	@Override
	public void delete(OrganizationDto dto) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void deleteById(Long pk) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public OrganizationDto findById(Long pk) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<OrganizationDto> getAll() {
		return organizationDtoUtil.convertModels2Dtos(organizationDao.getAll());
	}

	@Override
	public List<OrganizationDto> getAll(Page page) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void deleteAll(List<Long> pks) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<OrganizationDto> find(Page page, OrganizationDto organizationDto) {
		return organizationDtoUtil.convertModels2Dtos(organizationDao.findByOrganization(page, organizationDtoUtil.convertDto2Model(organizationDto)));
	}

	public void setOrganizationDao(OrganizationDao<Organization,Long> organizationDao) {
		this.organizationDao = organizationDao;
	}
}
